home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3321 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: command line argument help
  5. Date: 27 Jan 1996 15:57:32 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4ee3js$h57@umbc9.umbc.edu>
  8. References: <4edfth$ok@muss.CIS.McMaster.CA>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. In article <4edfth$ok@muss.CIS.McMaster.CA>,  <shadowfax> wrote:
  13. |> to all the c gods out there:
  14.  
  15. I don't see any, but I'll try to help anyway...
  16.  
  17. |> i am not having too much success with command line arguments.  i am 
  18. |> trying to make a simple sumation executable for dos.  i am using borland 
  19. |> c++ v3.1.  what i want as the end result is the user just types:
  20. |> 
  21. |> c:\> sum 6 3
  22. |> 
  23. |> and the executable would output an answer of 9. the following is my program:
  24. |> 
  25. |> #include <stdio.h>
  26. |> #include <stdlib.h>
  27. |> 
  28. |> int main(char *argv[])
  29.  
  30. Well there ya go! This is an illegal definition of main(). Instead use
  31. int main (int argc, char *argv[]).
  32.  
  33. |> {
  34. |>    int iSum = 0;
  35. |> 
  36. |>    iSum = atoi(argv[1]) + atoi(argv[2]);
  37. |>    printf("\nthe answer is %d", iSum);
  38.  
  39. You may want to end the printf() with a '\n' as well.
  40.  
  41. |>    return(0);
  42.  
  43. Good going...You get bonus points!
  44.  
  45. |> }
  46. |> 
  47. |> when i compile and run, it always outputs an anser of 0.  can anyone tell 
  48. |> me what's wrong?
  49.  
  50. Already did...Make the change to the definition of main() and you'll be good
  51. to go!
  52. -- 
  53. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  54.  
  55. Jonas J. Schlein  (schlein@gl.umbc.edu)
  56.